<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        button {
            width: 50px;
            height: 30px;
        }

        #box {
            height: 200px;
            width: 200px;
            background-color: blueviolet;
            border: 2px solid pink;
            position: absolute;
        }
    </style>
</head>

<body>
    <button id="btn">点击动画</button>
    <div id="box"></div>
    
    <script>
        var btn = document.getElementById('btn')
        var box = document.getElementById('box')
        var timer = null
        btn.onclick = function() {
            clearInterval(timer)
            timer = setInterval(function () {
                if(box.offsetLeft ===500){
                    clearInterval(timer)
                }else if(box.offsetTop === 500){
                    clearInterval(timer)
                }else{
                    box.style.left = box.offsetLeft + 10 + 'px'
                    box.style.top = box.offsetTop + 10 + 'px'
                }
            },30)
        }
    </script>
</body>

</html>